package mutation;

import GA.Chromosome;
import GA.Mutation;
import antTrail.AntTrailChromosome;
import antTrail.ProgramTree;

public class OperatorMutation extends Mutation {

	public OperatorMutation(double mutationProb) {
		super(mutationProb);
	}

	protected Chromosome mutate(Chromosome chrom) {
		ProgramTree tree = ((AntTrailChromosome) chrom).getTree();
		
		// First round: Search random operator to swap
		boolean mutated = tree.mutateOperator(true);
		
		// Second round: If there was no mutation, try to mutate first mutable operator
		// (it might be no mutation if there is no mutable node)
		if (!mutated)
			tree.mutateOperator(false);
			
		return chrom;
	}

}
